<?php

if ($_POST['Submit']) {
	$event_name = $_POST['event_name'];
	$short_description = $_POST['short_description'];
	$registration_start = strftime("%Y-%m-%d %H:%M:%S", strtotime($_POST['registration_start']));
	$registration_end = strftime("%Y-%m-%d %H:%M:%S", strtotime($_POST['registration_end']));
	$registration_limit = $_POST['registration_limit'] ? $_POST['registration_limit'] : 0;
	$event_start = strftime("%Y-%m-%d %H:%M:%S", strtotime($_POST['event_start'] . " " . $_POST['event_start_hour'] . ":" . $_POST['event_start_minute'] . " " . $_POST['event_start_ap']));
	$event_end = $event_start;
	//$event_end = strftime("%Y-%m-%d %H:%M:%S", strtotime($_POST['event_end'] . " " . $_POST['event_end_hour'] . ":" . $_POST['event_end_minute'] . " " . $_POST['event_end_ap']));
	$listing_status = $_POST['listing_status'];
	$address1 = $_POST['address1'];
	$address2 = $_POST['address2'];
	$city = $_POST['city'];
	$state = $_POST['state'];
	$zip = $_POST['zip'];

	global $current_user;
	$manager_id = $current_user->id;

	//insert event
	$event_sql = "INSERT into $em_event_table (manager_id, event_name, short_description, registration_start, registration_end, event_start, "
		. "event_end, registration_limit, listing_status, address1, address2, city, state, zip,  last_update_ts)"
		. " values('$manager_id', '$event_name', '$short_description', '$registration_start', '$registration_end', '$event_start', "
		. "'$event_end', '$registration_limit', '$listing_status', '$address1', '$address2', '$city', '$state', '$zip', "
		. "now())";
	$wpdb->query($event_sql);

	echo '<div id="message" class="updated fade"><p><strong>Event saved. <a href="' . EM_URL . 'event-list.php">return to event list.</a></strong></p></div>';
}

//Set default dates for events
$event;
$event->registration_start = current_time('mysql');
$event->registration_end = current_time('mysql');
$event->event_start = current_time('mysql');

?>

<div class="wrap">

<?php include('includes/admin-event-form.php') ?>

</div>